﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using WoSoft.PACS.Win.MyToolBars;
using WoSoft.PACS.Data.CheckData;
using DevComponents.DotNetBar.SuperGrid;
using WoSoft.PACS.Win.MyClass;

namespace WoSoft.PACS.Win.Forms.TjfxForms
{
    public partial class FrmCheckReport_Tjfx : FrmBase
    {

        private string appFormID = string.Empty;//当前选择病人的申请ID
        private string appFormType = string.Empty;//当前选择病人的检查类型

        public DateTime StartTime { get; private set; }
        public DateTime EndTime { get; private set; }
        public string DepartmentID { get; private set; }
        public int HasApp { get; private set; }
        public int HasBD { get; private set; }
        public int HasExecuteing { get; private set; }
        public int HasFinish { get; private set; }
        public string PatientID { get; private set; }
        public string PatientName { get; private set; }
        public int HasYingx { get; private set; }
        public int HasYangx { get; private set; }
        public int HasYsh { get; private set; }
        public int HasWsh { get; private set; }

        public FrmCheckReport_Tjfx()
        {
            InitializeComponent();
        }

        public FrmCheckReport_Tjfx(RibbonBar ribar)
            : base(ribar)
        {
            InitializeComponent();
        }

        public override List<MyToolBars.OperationModel> Operations()
        {
            List<OperationModel> functionInfos = new List<OperationModel>();

            //检索数据
            var readButton = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "检索数据",
                Image = global::WoSoft.PACS.Win.Properties.Resources.scroll_view,
                ClickEvent = new EventHandler(ReadButton),
            };
            functionInfos.Add(readButton);

            //查看报告
            //var viewReport = new OperationModel()
            //{
            //    ID = Guid.NewGuid().ToString(),
            //    Name = "查看报告",
            //    Image = global::WoSoft.PACS.Win.Properties.Resources.find,
            //    ClickEvent = new EventHandler(ViewReport),
            //};
            //functionInfos.Add(viewReport);

            //导出数据
            var outPutButton = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "导出数据",
                Image = global::WoSoft.PACS.Win.Properties.Resources.export1,
                ClickEvent = new EventHandler(OutPutButton),
            };
            functionInfos.Add(outPutButton);

            //刷新数据
            var refresh = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "刷新数据",
                Image = global::WoSoft.PACS.Win.Properties.Resources.refresh,
                ClickEvent = Refresh,
            };
            functionInfos.Add(refresh);

            //退出
            var exit = new OperationModel()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "退出",
                Image = global::WoSoft.PACS.Win.Properties.Resources.exit,
                ClickEvent = ExitClick
            };
            functionInfos.Add(exit);

            return functionInfos;
        }

        //检索数据
        private void ReadButton(object sender, EventArgs e)
        {
            this.StartTime = this.dtStartTime.Value;
            this.EndTime = this.dtEndTime.Value;
            this.DepartmentID = this.cbDepartment.SelectedValue != null ? this.cbDepartment.SelectedValue.ToString() : "";


            CheckApp checkApp = new CheckApp();

            DataTable dt = checkApp.GetCheckListResult_Gzl(StartTime, EndTime, DepartmentID);
            this.superGridControl1.PrimaryGrid.DataSource = dt;
        }

        //查看报告
        private void ViewReport(object sender, EventArgs e)
        {
            //if (this.appFormID == "") return;
            //SubForms.FrmReadReport report = new SubForms.FrmReadReport(this.appFormID);
            //SubForms.FrmReportView report = new SubForms.FrmReportView(this.appFormID,this.appFormType);
            //report.Show();
        }

        //导出数据
        private void OutPutButton(object sender, EventArgs e)
        {
            var rows = this.superGridControl1.PrimaryGrid.Rows.Count;
            if (rows < 1) return;

            DataGridViewExport.SuperGridControlShowToExcel(superGridControl1, false);
        }

        //刷新数据
        private void Refresh(object sender, EventArgs e)
        {
            ReadButton(sender, e);
        }

        //退出
        private void ExitClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmCheckReportSearch_Load(object sender, EventArgs e)
        {
            //加载部门
            this.LoadDepartment(this.cbDepartment);

            this.dtStartTime.Value = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));
            this.dtEndTime.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(1).AddSeconds(-1);

            //ReadButton(sender, e);
        }

        private void superGridControl1_SelectionChanged(object sender, DevComponents.DotNetBar.SuperGrid.GridEventArgs e)
        {
            //var rows = this.superGridControl1.PrimaryGrid.GetSelectedRows();
            //if (rows == null || rows.Count == 0)
            //{
            //    return;
            //}
            //var row = rows[0];
            //GridRow gridRow = row as GridRow;
            //if (gridRow != null)
            //{
            //    this.appFormID = gridRow["colID"].Value.ToString();
            //    this.appFormType= gridRow["colType"].Value.ToString();
            //}
        }

        private void superGridControl1_CellDoubleClick(object sender, GridCellDoubleClickEventArgs e)
        {
            //ViewReport(null, null);
        }

        private void superGridControl1_Click(object sender, EventArgs e)
        {
            //var rows = this.superGridControl1.PrimaryGrid.GetSelectedRows();
            //if (rows == null || rows.Count == 0)
            //{
            //    return;
            //}
            //var row = rows[0];
            //GridRow gridRow = row as GridRow;
            //if (gridRow != null)
            //{
            //    Clipboard.SetDataObject(gridRow["备注"].Value);
            //}
        }

        private void 查看报告ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //ViewReport(null, null);
        }

        private void 修改报告时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //var rows = this.superGridControl1.PrimaryGrid.GetSelectedRows();
            //if (rows == null || rows.Count == 0)
            //{
            //    return;
            //}
            //var row = rows[0];
            //GridRow gridRow = row as GridRow;
            //if (gridRow != null)
            //{
            //    FrmReportEditTime frm = new FrmReportEditTime(gridRow["colID"].Value.ToString(), gridRow["报告时间"].Value.ToString());
            //    frm.ShowDialog();
            //}
        }
    }
}
